package com.shqcjd.generalplatformprojectclient.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.itheima.roundedimageview.RoundedImageView;
import com.shqcjd.generalplatformprojectclient.R;
import com.shqcjd.generalplatformprojectclient.model.pojo.FileBean;
import com.shqcjd.generalplatformprojectclient.ui.activity.ImageActivity;

import java.util.ArrayList;
import java.util.List;

public class EquipmentInfoPicAdapter extends RecyclerView.Adapter<EquipmentInfoPicAdapter.MyViewHolder> {
    private Context context;
    private List<FileBean> mList;

    public EquipmentInfoPicAdapter(Context context, List<FileBean> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_info_equipment, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Glide.with(context).load(mList.get(position).url).apply(new RequestOptions().placeholder(R.mipmap.login_pic)).into(holder.iv_item_equiment_info);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<String> iList = new ArrayList<>();
                for(int i=0; i<mList.size(); i++){
                    iList.add(mList.get(i).url);
                }
                Intent it = new Intent(context, ImageActivity.class);
                it.putStringArrayListExtra("imageList",  iList);
                it.putExtra("pos", position);
                context.startActivity(it);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        private RoundedImageView iv_item_equiment_info;
        public MyViewHolder(View itemView) {
            super(itemView);
            iv_item_equiment_info = itemView.findViewById(R.id.iv_item_equiment_info);
        }
    }
}

